
#pragma once

#include "../Main.h"

#include "../TypedList.h"
#include "ExposedVariable.h"

enum SCRIPT_OUTPUTS
{
	SCRIPT_OUTPUT_INIT,
	SCRIPT_OUTPUT_UPDATE,
	SCRIPT_OUTPUT_RENDER,
	
	NUM_SCRIPT_OUTPUTS
};

//template <class ExposedVariable> class TypedList;
//class ExposedVariable;

class Element
{
	public:

		Element();
		Element( const Element* pxElement );
		~Element();
	
		void Clear();

		bool SaveToFile( FILE* pxFile );
		bool ReadFromFile( FILE* pxFile );

		bool SaveToTemplateFile( const char* const szFilename );
		bool ReadFromTemplateFile( const char* const szFilename );

		char* GetCodeString() { return m_szCodeString; }
		void SetCodeString( const char* szCodeString );

		void Init();
		void Update();
		void Render();

		static const Element* GetActiveElement();

		const char* GetName() { return m_szName; }
		void SetName( const char* szName );

		const char* GetScriptOutput( SCRIPT_OUTPUTS eOutput ) { return m_aszScriptOutput[eOutput]; }

		void SetIsUILocked( bool bIsUILocked ) { m_bLockedControls = bIsUILocked; };
		bool GetIsUILocked() { return m_bLockedControls; };
	
		void SetIsGroup( bool bGroup );
		bool IsGroup() const;
	
		bool IsIniting() const;
		
		bool NeedsToCreateControls() { return m_bCreateControls; }; 
		
		ExposedVariable* GetExposedVariable( int iIndex );
		const ExposedVariable* GetExposedVariable( const char* szName ) const;
		int GetNumExposedVariables();
	
		void AddExposedVariable( const char* szName, const EXPOSED_VARIABLE_TYPE xVariableType, float fInitValue, float fSliderMin = 0.0f, float fSliderMax = 1.0f ) const;
		void AddExposedVariable( ExposedVariable* pxExposedVariable );
		void RemoveExposedVariable( int iIndex );
	
	protected:

		char* m_szName;
		char* m_szCodeString;
		
		char* m_aszScriptOutput[ NUM_SCRIPT_OUTPUTS ];
		
		u_int m_uCodeLength;
		bool m_bGroup;
		bool m_bNeedExpose;
		bool m_bCreateControls;
		bool m_bIniting;
		bool m_bLockedControls;
	
		TypedList<ExposedVariable>* m_pxExposedVariables; 

		// The element which is init/render/updating
		static Element* s_pxActiveElement;
};

// eof
